package com.cn.busi;

import java.util.List;

import io.swagger.annotations.Api;

import org.junit.runners.Parameterized.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cn.model.Stu;
import com.cn.service.StuService;





/**
 * 
 * 【学生】业务控制器
 * 
 * @author ZSL
 *
 */
@RestController
@RequestMapping(value = "/api/v2")
@Api(description = "【学生】业务控制器")
public class StuController {
	
	
	@Autowired
	private StuService stuService;
	
	/**
	 * 日志
	 */
	private Logger logger = LoggerFactory.getLogger(StuController.class);
	
	/**
	 * 
	 * 新增学生
	 * 
	 * @param user
	 */
	@RequestMapping(value = "/students", method = RequestMethod.POST)
	
	public void addStu(@RequestBody Stu stu) {
		 stuService.addStu(stu);
		 
		//userService.addUser(user);
		logger.info("增加用户信息："+stu);

	}
	
	/**
	 * 
	 * 删除学生
	 * 
	 * @param user
	 */
	@RequestMapping(value = "/students", method = RequestMethod.DELETE)
	
	public void delStu(@RequestParam("id") String id ,@RequestParam("name")  String name) {
		logger.info("删除用户用户信息："+id+name);
		stuService.delStu(id,name);
		//userService.addUser(user);
		logger.info("删除用户用户信息："+name);

	}
	
	
	/**
	 * 
	 * 更新学生
	 * 
	 * @param user
	 */
	@RequestMapping(value = "/students/{id}/{name}", method = RequestMethod.PUT)
	
	public void updataStu(@PathVariable("id") String id ,@PathVariable("name")  String name,@RequestBody Stu stu) {
		

		stuService.updateStu(stu);
		//userService.addUser(user);

	}
	
	/**
	 * 
	 * 查询所有学生
	 * 
	 * @param user
	 */
	@RequestMapping(value = "/students", method = RequestMethod.GET)
	
	public List<Stu> getStu() {
		
		return stuService.getStu1();
		//userService.addUser(user);

	}

}
